package AcWing.每日一题2025;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author ZhuYi
 * @create 2025/3/24 10:22
 */
public class 密接牛追踪2_5438 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        int cnt = 0;
        int totalOne = 0;
        ArrayList<Integer> one = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c == '1') {
                cnt++;
                totalOne++;
            }
            if (c == '0' && i > 0 && s.charAt(i - 1) == '1') {
                one.add(cnt);
                cnt = 0;
            }
        }
        if (cnt > 0) one.add(cnt);

        // 寻找最大天数
        int day = Integer.MAX_VALUE;
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '1') {
                if (i == 0 || i + one.get(j) == n) day = Math.min(day, one.get(j) - 1);
                else if (one.get(j) % 2 != 0) day = Math.min(day, one.get(j) / 2);
                else if (one.get(j) % 2 == 0) day = Math.min(day, (one.get(j) - 2) / 2);
                i = i + one.get(j++) - 1;
            }
        }

        if (day == 0) {
            System.out.println(totalOne);
            return;
        }
        int ans = 0;
        for (int i = 0; i < one.size(); i++) {
            if (one.get(i) % (day * 2 + 1) == 0) ans += one.get(i) / (day * 2 + 1);
            else ans += (int) Math.ceil(one.get(i) * 1.0 / (day * 2 + 1));
        }

        System.out.println(ans);
    }
}
